package com.zhaiweijia.eurekaproducer.controller;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhaiweijia.dto.UserDto;
import com.zhaiweijia.eurekaproducer.entity.User;
import com.zhaiweijia.eurekaproducer.service.IUserService;
import com.zhaiweijia.vo.ResultEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhaiwj
 * @since 2021-02-21
 */
@RestController
@RequestMapping("/user")
@Slf4j
public class UserController {

    @Autowired
    private IUserService iUserService;

    @Value("${foo}")
    private String foo;

    @RequestMapping("list")
    public Object getUserList(@RequestBody UserDto userDto){
        log.info("---------------"+foo);
        System.out.println(userDto.getPageNum());
        PageHelper.startPage(userDto.getPageNum(),userDto.getPageSize()) ;

        QueryWrapper<User> wrapper = new QueryWrapper<>();
        if(userDto.getName()!=null && userDto.getName()!=""){
            wrapper.like("name",userDto.getName());
        }
        List<User> users = iUserService.list(wrapper);

        PageInfo<User> info=new PageInfo<>(users);
        return ResultEntity.ok("200","操作成功",info);

    }

}

